import java.util.HashMap;
import java.util.Scanner;

//改名字
public class MainD {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr1 = new int[n];
        int[] arr2 = new int[m];

        for (int i = 0; i < n; i++) {
            arr1[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            arr2[i] = sc.nextInt();
        }

        int count = 0;
        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int s = arr1[i] + arr2[j];
                if (s <= n + m) {
                    if (isPrims(s)) {
                        if (!map.containsKey(s)) {
//                            System.out.println(s);
                            count++;
                            map.put(s, 1);
                        }
                    }
                }
            }
        }

        System.out.println(count);

        sc.close();
    }

    public static boolean isPrims(int num) {
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
